import { NameSpace } from 'utils';
import exceed from 'utils/apimap';
import { getFeature } from 'utils/features';

const ns = NameSpace('settings');
export const UPDATE_DATA = ns('UPDATE_DATA');
// 获取企业当前套餐
export const ENTERPRISE_PACKAGE = ns('ENTERPRISE_PACKAGE');

export function updateData(data) {
  return (dispatch) => {
    dispatch({
      type: UPDATE_DATA,
      data,
    });
  };
}

// 获取企业当前套餐
export function getOrgplan() {
  return (dispatch) => {
    return new Promise((resolve, reject) => {
      if (!getFeature('organization.setting.enterprise_package')) {
        reject();
        return;
      }
      exceed.fetch({ api: 'organization.orgplan' }).then((res) => {
        resolve(res);
        dispatch({
          type: ENTERPRISE_PACKAGE,
          data: res,
        });
      });
    });
  };
}
